'''
Created on Jan 27, 2012

@author: pedro
'''
import math

class Pulse(object):
    
    def __init__(self, voltage, pulse_duration):
        self.voltage = voltage
        self.pulse_duration = pulse_duration
        self.timeOn = -1
        self.on = True
        
    def __iter__(self):
        return self
    
    def next(self):
        if self.on == True:
            self.timeOn += 1
            return self.voltage
        else:
            return 0.00
        
    def set_on(self, on):
        self.on = on 

class SquarePulse(Pulse):
    
    def __init__(self, voltage, pulse_duration):
        Pulse.__init__(self, voltage, pulse_duration)       

class RCFilteredPulse(Pulse):
    '''
    classdocs
    '''
    
    def __init__(self,voltage,pulse_duration,tau1,tau2):
        '''
        Constructor
        '''
        self.voltage = voltage
        self.on = True
        self.pulse_duration = pulse_duration
        self.tau1 = tau1
        self.tau2 = tau2
        self.timeOn = -1
    
    def next(self):
        '''
        Docstring
        '''
        if self.on == True:
            self.timeOn += 1
            return self.voltage*(1.00 - math.exp((-self.timeOn)/self.tau1)) if self.timeOn < self.pulse_duration else self.voltage*math.exp((-(self.timeOn-self.pulse_duration))/self.tau2)
        else:
            return 0.00
        
    def set_on(self, on):
        if self.on == False & on == True:
            self.timeOn = 0
        else:
            self.on = on